package com.ttxs.common.core.vo;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

@Data
@Accessors(chain = true)
public class R<T> {
    private int code;
    private String msg;
    private T data;

    public static R ok() {
        return new R().setCode(HttpStatus.OK.value()).setMsg("success");
    }

    public static R ok(String msg) {
        return new R().setCode(HttpStatus.OK.value()).setMsg(msg);
    }

    public static<T> R ok(T data) {
        return new R().setCode(HttpStatus.OK.value()).setMsg("success").setData(data);
    }

    public static R error() {
        return new R().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg("error");
    }

    public static R error(String msg) {
        return new R().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg(msg);
    }

    public static R error(int code, String msg) {
        return new R().setCode(code).setMsg(msg);
    }

}
